from fastapi.encoders import jsonable_encoder
from schema.inner_use_schema.ali_pay_schema import AliPayTradeQueryResponseModel
from service.base import Service
from common.model.payment.transaction import AliPayTransaction


class TransactionService(Service):

    async def add_new_ali_translation(self, tenant_id, req_model: AliPayTradeQueryResponseModel):
        return await AliPayTransaction.add_new_instance(self.mgw, **dict(tenant_id=tenant_id,
                                                                         transaction_id=req_model.trade_no,
                                                                         order_sn=req_model.out_trade_no,
                                                                         buyer_user_id=req_model.buyer_user_id,
                                                                         buyer_pay_amount=req_model.buyer_pay_amount,
                                                                         total_amount=req_model.total_amount,
                                                                         receive_time=req_model.send_pay_date,
                                                                         trade_status=req_model.trade_status,
                                                                         snapshot=jsonable_encoder(req_model.dict())))
